Skip to content

Link static libtiff dependencies#9635

Open
hholst80 wants to merge 1 commit into
python-pillow:mainfrom
hholst80:codex/static-libtiff-deps
Open

Link static libtiff dependencies#9635
hholst80 wants to merge 1 commit into
python-pillow:mainfrom
hholst80:codex/static-libtiff-deps

Conversation

@hholst80
Copy link
Copy Markdown

What changed

This updates the Pillow source build to include libtiff's pkg-config static link dependencies when the detected TIFF library is an archive.

For dynamic libtiff builds, behavior is unchanged. For static-only libtiff builds, Pillow now reads pkg-config --libs --static for the libtiff module that resolved TIFF_ROOT, adds its -L directories, appends private -l dependencies after -ltiff, and passes through other linker flags such as -pthread.

Why

On systems with /usr/lib/libtiff.a but no libtiff.so, Pillow previously linked PIL._imaging with -ltiff -ljpeg -lz only. The build succeeded, but importing PIL._imaging failed with unresolved libtiff private dependency symbols such as ZSTD_compressStream.

Addresses #9615.

Validation

Reproduced before the fix on a host with:

  • /usr/lib/libtiff.a
  • no libtiff.so*
  • pkg-config --libs libtiff-4 -> -ltiff
  • pkg-config --libs --static libtiff-4 -> -ltiff -lzstd -lm -lzstd -llzma -pthread -lpthread -ljpeg -lz

After the fix:

  • MAX_CONCURRENCY=1 python -m pip install -v --no-build-isolation -C tiff=enable .
  • python -c "import PIL._imaging"
  • python selftest.py -> 59 tests passed

@hholst80
Copy link
Copy Markdown
Author

hholst80 commented May 21, 2026

Validated that it does not mess up a so Ubuntu 24.04 normy build:

  docker run --rm -v /tmp/repro:/src -w /src ubuntu:24.04 bash -lc '
  set -eux
  rm -rf build src/pillow.egg-info
  apt-get update
  DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends build-essential python3-dev python3-venv python3-pip pkg-config libtiff-dev libjpeg-dev zlib1g-dev libfreetype6-dev liblcms2-dev libwebp-dev libopenjp2-7-dev libimagequant-dev libraqm-dev libxcb1-dev binutils file ca-certificates
  python3 -m venv /tmp/pillow-pr9635-venv
  /tmp/pillow-pr9635-venv/bin/python -m pip install -U pip setuptools wheel pybind11
  MAX_CONCURRENCY=2 /tmp/pillow-pr9635-venv/bin/python -m pip install -v --no-build-isolation --no-cache-dir .
  so=$(/tmp/pillow-pr9635-venv/bin/python -c "import PIL._imaging, pathlib; print(pathlib.Path(PIL._imaging.__file__))")
  printf "SO=%s\n" "$so"
  /tmp/pillow-pr9635-venv/bin/python -c "from PIL import features; import PIL, pathlib; print(\"Pillow\", PIL.__version__); print(\"libtiff feature\", features.check(\"libtiff\")); print(\"libtiff version\", features.version(\"libtiff\")); print(\"PIL package\", pathlib.Path(PIL.__file__).parent)"
  file "$so"
  readelf -d "$so" | egrep "NEEDED|RPATH|RUNPATH" || true
  ldd "$so" | egrep "tiff|jpeg|z|lzma|zstd|webp|jbig|deflate|not found" || true
  '
[...]
Successfully built pillow
Installing collected packages: pillow
Successfully installed pillow-12.3.0.dev0
++ /tmp/pillow-pr9635-venv/bin/python -c 'import PIL._imaging, pathlib; print(pathlib.Path(PIL._imaging.__file__))'
+ so=/tmp/pillow-pr9635-venv/lib/python3.12/site-packages/PIL/_imaging.cpython-312-x86_64-linux-gnu.so
+ printf 'SO=%s\n' /tmp/pillow-pr9635-venv/lib/python3.12/site-packages/PIL/_imaging.cpython-312-x86_64-linux-gnu.so
SO=/tmp/pillow-pr9635-venv/lib/python3.12/site-packages/PIL/_imaging.cpython-312-x86_64-linux-gnu.so
+ /tmp/pillow-pr9635-venv/bin/python -c 'from PIL import features; import PIL, pathlib; print("Pillow", PIL.__version__); print("libtiff feature", features.check("libtiff")); print("libtiff version", features.version("libtiff")); print("PIL package", pathlib.Path(PIL.__file__).parent)'
Pillow 12.3.0.dev0
libtiff feature True
libtiff version 4.5.1
PIL package /tmp/pillow-pr9635-venv/lib/python3.12/site-packages/PIL
+ file /tmp/pillow-pr9635-venv/lib/python3.12/site-packages/PIL/_imaging.cpython-312-x86_64-linux-gnu.so
/tmp/pillow-pr9635-venv/lib/python3.12/site-packages/PIL/_imaging.cpython-312-x86_64-linux-gnu.so: ELF 64-bit LSB shared object, x86-64, version 1 (SYSV), dynamically linked, BuildID[sha1]=c0e36e40acc88ec2925237945d64481c0fa60431, with debug_info, not stripped
+ readelf -d /tmp/pillow-pr9635-venv/lib/python3.12/site-packages/PIL/_imaging.cpython-312-x86_64-linux-gnu.so
+ egrep 'NEEDED|RPATH|RUNPATH'
 0x0000000000000001 (NEEDED)             Shared library: [libtiff.so.6]
 0x0000000000000001 (NEEDED)             Shared library: [libjpeg.so.8]
 0x0000000000000001 (NEEDED)             Shared library: [libopenjp2.so.7]
 0x0000000000000001 (NEEDED)             Shared library: [libz.so.1]
 0x0000000000000001 (NEEDED)             Shared library: [libimagequant.so.0]
 0x0000000000000001 (NEEDED)             Shared library: [libxcb.so.1]
 0x0000000000000001 (NEEDED)             Shared library: [libc.so.6]
+ ldd /tmp/pillow-pr9635-venv/lib/python3.12/site-packages/PIL/_imaging.cpython-312-x86_64-linux-gnu.so
+ egrep 'tiff|jpeg|z|lzma|zstd|webp|jbig|deflate|not found'
	libtiff.so.6 => /lib/x86_64-linux-gnu/libtiff.so.6 (0x00007f5af17ee000)
	libjpeg.so.8 => /lib/x86_64-linux-gnu/libjpeg.so.8 (0x00007f5af176b000)
	libz.so.1 => /lib/x86_64-linux-gnu/libz.so.1 (0x00007f5af16ee000)
	libwebp.so.7 => /lib/x86_64-linux-gnu/libwebp.so.7 (0x00007f5af1424000)
	libzstd.so.1 => /lib/x86_64-linux-gnu/libzstd.so.1 (0x00007f5af136a000)
	liblzma.so.5 => /lib/x86_64-linux-gnu/liblzma.so.5 (0x00007f5af1338000)
	libjbig.so.0 => /lib/x86_64-linux-gnu/libjbig.so.0 (0x00007f5af129f000)
	libdeflate.so.0 => /lib/x86_64-linux-gnu/libdeflate.so.0 (0x00007f5af128c000)
root@neo ~
# 

@hholst80 hholst80 marked this pull request as ready for review May 21, 2026 15:46
@hholst80 hholst80 changed the title [codex] Link static libtiff dependencies Link static libtiff dependencies May 21, 2026
@radarhere radarhere added the TIFF label May 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants